package cn.wolfcode.luowowo.website.controller;

import cn.wolfcode.luowowo.article.service.ITravelCommendService;
import cn.wolfcode.luowowo.article.service.ITravelService;
import cn.wolfcode.luowowo.common.query.TravelQueryObject;
import cn.wolfcode.luowowo.member.domain.UserInfo;
import cn.wolfcode.luowowo.website.annotation.LoginUser;
import cn.wolfcode.luowowo.website.annotation.RequiredLogin;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class IndexController {

    @Reference
    private ITravelCommendService travelCommendService;

    @Reference
    private ITravelService travelService;

    @RequestMapping("/")
    public String index(Model model) {
        //tcs 推荐游记5篇
        model.addAttribute("tcs", travelCommendService.listTop5());
        //scs 推荐的攻略5篇
        model.addAttribute("scs", travelCommendService.listTop5());

        return "index/index";
    }

    // 分页显示游记 index/travelPage
    @RequestMapping("index/travelPage")
    public String travelPage(TravelQueryObject qo, Model model) {
        model.addAttribute("pageInfo", travelService.query(qo));
        return "index/travelPageTpl";
    }


    @RequestMapping("/123")
    @ResponseBody
    public Object index(@LoginUser UserInfo userInfo) {
        return userInfo;
    }

    @RequiredLogin
    @RequestMapping("/3")
    @ResponseBody
    public Object index3(@LoginUser UserInfo userInfo) {
        System.out.println(userInfo);
        return userInfo;
    }

}
